home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / latexinfo / manual / latex2dvi < prev    next >
Text File  |  1992-02-15  |  5KB  |  205 lines

  1. #!/bin/sh
  2. #
  3. # latex2dvi - prepare LaTeXinfo files for printing.  
  4. #
  5. # Copyright (C) 1990, 1991 Free Software Foundation.
  6. #
  7. # Roland McGrath <roland@gnu.ai.mit.edu>
  8. # Converted To LaTeXinfo by Mike Clarkson <mike@apl.ists.ca>
  9. # Version 0.10
  10. # 24 Sep 91
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 1, or (at your option)
  15. # any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. # GNU General Public License for more details.
  21. #
  22. # A copy of the GNU General Public License can be obtained from this
  23. # program's author (send electronic mail to roland@ai.mit.edu) or from
  24. # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  25. # 02139, USA.
  26.  
  27. if [ $# -eq 0 ]; then
  28.   echo "Usage: `basename $0` FILE ..." >&2
  29.   exit 1
  30. fi
  31.  
  32. # The names of your LaTeX commands.
  33. LATEXINDEX=latexindex
  34. BIBTEX=bibtex
  35. LATEX=latex
  36.  
  37. for file in $*; do
  38.   if [ ! -f $file ] ; then
  39.     if [ ! -f $file.tex ] ; then
  40.         echo `basename $0`: File not found - $file
  41.         echo Please give the full file name.
  42.         exit 1
  43.     else
  44.        file=$file.tex
  45.        fi
  46.         fi
  47.   base="`basename $file .latexinfo | sed -e 's/\.texi$//' -e 's/\.tex$//'`"
  48.  
  49.   # Find all existing index files corresponding to FILE.
  50.   idx_files="`echo ${base}.??`"
  51.   if [ "$idx_files" = "${base}.??" ] ; then
  52.     # Maybe it's new!
  53.     if grep '^\\newindex{' $file > /dev/null ; then
  54.     changed=yes
  55.     else
  56.        idx_files=''
  57.     fi
  58.   else
  59.     # Ignore files with two-letter extensions that don't look like index files.
  60.     oidx_files="$idx_files"
  61.     idx_files=''
  62.     for idx_file in $oidx_files; do
  63.       if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
  64.         # It starts with a backslash, so it's probably an index file.
  65.     idx_files="$idx_files $idx_file"
  66.       fi
  67.     done
  68.   fi
  69.  
  70.   if grep '^\\bibliography{' $file > /dev/null ; then
  71.     bibtex=yes
  72.     bib_file=$base.bbl
  73.     if [ -f $bib_file ] ; then
  74.         # Save a copy of the old bbl file.
  75.         cp ${bib_file} ${bib_file}O
  76.     else
  77.              # There wasn't a bbl before so run it again anyway.
  78.              changed=yes
  79.     fi
  80.   fi
  81.  
  82.   for idx_file in $idx_files; do
  83.     # Save a copy of the old index file.
  84.     cp ${idx_file} ${idx_file}O
  85.   done
  86.  
  87.   if [ "$idx_files" != "" ]; then
  88.     # Run LATEXINDEX on the index files.
  89.     echo ${LATEXINDEX} $idx_files
  90.     ${LATEXINDEX} $idx_files
  91.   fi
  92.  
  93.   aux_file=$base.aux
  94.   if [ -f $aux_file ] ; then
  95.     # Save a copy of the old aux file.
  96.     cp ${aux_file} ${aux_file}O
  97.   else
  98.     # There wasn't a aux before so run it again anyway.
  99.     changed=yes
  100.   fi
  101.  
  102.   # Run LaTeX on FILE.
  103.   echo ${LATEX} $file
  104.   if ${LATEX} $file; then
  105.  
  106.     # Find all the index files that exist now,
  107.     # so we can see if there are any new ones.
  108.     new_idx_files="`echo ${base}.??`"
  109.     if [ "$new_idx_files" = "${base}.??" ]; then
  110.       new_idx_files=''
  111.     else
  112.       oidx_files="$idx_files"
  113.       new_idx_files=''
  114.       for idx_file in $oidx_files; do
  115.     if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
  116.       # It starts with a backslash, so it's probably an index file.
  117.       new_idx_files="$new_idx_files $idx_file"
  118.     fi
  119.       done
  120.     fi
  121.  
  122.     if [ "$new_idx_files" != "$idx_files" ]; then
  123.       # There are some new index files.
  124.       changed=yes
  125.       idx_files="$new_idx_files"
  126.     else
  127.       # Run through all the index files, comparing them to the old ones.
  128. #      changed=no
  129.       for idx_file in $idx_files; do
  130.     # Compare the old and new index files.
  131.     cmp -s ${idx_file}O ${idx_file}
  132.     status=$?
  133.  
  134.     # Remove the old index file.
  135.     rm -f ${idx_file}O
  136.  
  137.     if [ $status -ne 0 ]; then
  138.       # The index file has changed.
  139.       changed=yes
  140.     fi
  141.       done    # for idx_file
  142.     fi
  143.  
  144.     if [ "$bibtex" = "yes" ] ; then
  145.        echo ${BIBTEX} $base
  146.        if ${BIBTEX} $base ; then
  147.           if [ -f $bib_file ] ; then
  148.              # Compare the old and new index files.
  149.              cmp -s ${bib_file} ${bib_file}O
  150.              status=$?
  151.      
  152.              # Remove the old index file.
  153.              rm -f ${bib_file}O
  154.      
  155.              if [ $status -ne 0 ]; then
  156.                # The index file has changed.
  157.                changed=yes
  158.              fi
  159.           fi
  160.        else
  161.          # BibTeX failed.  Remove the copies of the backup bbl file.
  162.          if [ -f ${bib_file}O ] ; then
  163.              rm -f ${bib_file}O
  164.          fi
  165.        fi
  166.     fi
  167.   
  168.     # Compare the old and new aux files.
  169.     if [ -f ${aux_file}O ] ; then
  170.     cmp -s ${aux_file}O ${aux_file}
  171.     status=$?
  172.  
  173.     # Remove the old aux file.
  174.     rm -f ${aux_file}O
  175.  
  176.     if [ $status -ne 0 ]; then
  177.       # The aux file has changed.
  178.       changed=yes
  179.     fi
  180.     else
  181.      # The aux file has changed.
  182.          changed=yes
  183.     fi
  184.  
  185.    if [ "$changed" = "yes" ]; then
  186.       # Some index file changed.  Run LATEXINDEX and LaTeX again.
  187.  
  188.       # Run LATEXINDEX on the index files.
  189.       echo ${LATEXINDEX} $idx_files
  190.       if ${LATEXINDEX} $idx_files; then
  191.     # Run LaTeX2dvi on FILE.
  192.     echo $0 $file
  193.     $0 $file
  194.       fi
  195.     fi
  196.   else
  197.     # LaTeX failed.  Remove the copies of the index files.
  198.     for idx_file in $idx_files; do
  199.       rm -f ${idx_file}O
  200.     done
  201.   fi
  202.  
  203. done       # for file
  204.  
  205.